﻿using AutoMapper;
using B.S.BaseData.Domain.Entities.RBAC;
using B.S.BaseData.ErrorCode;
using B.S.BaseData.ErrorCode.ErrorCodes;
using B.S.BaseData.Infrastructure.Implements;
using B.S.BaseData.Infrastructure.Interfaces;
using B.S.DataBase.EFCoreServiers.IServices.Users;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace B.S.DataBase.EFCoreServiers.Services.Users
{
    public class UserServices : IUserServices
    {
        private readonly IUserRepository user;
        private readonly IMapper mapper;

        public UserServices(IUserRepository user, IMapper mapper)
        {
            this.user = user;
            this.mapper = mapper;
        }
        public async Task<ApiResult<ApiPaging<GetUserReponseDtos>>> GetUser(GetUserDtos getUser)
        {
            try
            {
                var pageResult = await user.GetPageListAsync(getUser.pageIndex, getUser.pageSize, null);
                var dtoList = mapper.Map<IList<GetUserReponseDtos>>(pageResult.Data);
                var pagingDto = new ApiPaging<GetUserReponseDtos>(pageResult.TotalCount, pageResult.TotalPage, dtoList);
                return ApiResult<ApiPaging<GetUserReponseDtos>>.Success(pagingDto, StatusCodeEnum.Ok);
            }
            catch (Exception ex)
            {
                return ApiResult<ApiPaging<GetUserReponseDtos>>.Fail("获取用户列表失败", StatusCodeEnum.Exception);
            }
        }


      






    }
}
